<?php

namespace App\Models;

use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\Model;

class Order extends Model
{
    use HasDateTimeFormatter;

    // 售卖类型
    const SELL_CAMP = 1;//门票
    const SELL_LEASE = 2;//租赁
    const SELL_FOOD = 3;//美食
    const SELL_COMBO = 4;//套餐

    // 支付类型
    const PAY_TYPE_WECHAT = 1;//微信

    // 状态
    const STATE_REFUNDED = -4;//已退款
    const STATE_REFUNDING = -3;//退款中
    const STATE_PAY_EXPIRE = -1;//支付过期
    const STATE_WAIT_PAY = 1;//待支付
    const STATE_WAIT_USE = 2;//待使用
    const STATE_USE_EXPIRE = 3;//使用过期
    const STATE_USED = 4;//已使用

    protected $table = 'order';

    public static function getSn()
    {
        $sn = date('YmdHis') . rand(1000, 9999);
        return $sn;
    }

    public static function sellTypeMap()
    {
        return [self::SELL_CAMP => '门票', self::SELL_LEASE => '租赁', self::SELL_FOOD => '美食', self::SELL_COMBO => '套餐'];
    }

    public static function payTypeMap()
    {
        return [self::PAY_TYPE_WECHAT => '微信'];
    }

    public static function stateMap()
    {
        return [
            self::STATE_WAIT_PAY => '待支付',
            self::STATE_WAIT_USE => '待使用',
            self::STATE_USE_EXPIRE => '使用过期',
            self::STATE_USED => '已使用',
            self::STATE_PAY_EXPIRE => '支付过期',
            self::STATE_REFUNDING => '退款中',
            self::STATE_REFUNDED => '已退款'
        ];
    }
}
